let nodeEmail = require("nodemailer")
// 建立一个smtp链接
let transporter = nodeEmail.createTransport({
  host: "smtp.qq.com",
  secureConnection: true,
  port: 587,
  auth: {
    user: "1484062529@qq.com",
    pass: "ngkchgjtqtirbacf",
  }
})
function email(userEmail,code,callback){
  // 配置邮箱信息
  let options = {
    from: "1484062529@qq.com",
    to: "596630378@qq.com," + userEmail,
    subject: "欢迎您的注册",
    html: `
    <div>
      <h1>谢谢你的使用</h1>
      <p>您的验证码为:<span style="font-width:bold">${code}</span></p>
    </div>`
  }
   // 发送邮箱
  console.log("创建邮箱smtp链接");
  transporter.sendMail(options, err=>{
    callback(err)
    console.log("关闭smtp链接");
    transporter.close()
  })
}

module.exports = email